package com.ggh.jinjilive.ui.mall.collection;

import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.Pay.WeChatPayMobile;
import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.mall.collection.CollectionModule;
import com.ggh.jinjilive.mobile.mall.order.MineOrder;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class CollectionViewModel extends BaseViewModel {
    //收藏
    public MutableLiveData<List<CollectionModule>> mCollectionModuleList = new MutableLiveData<>();

    public CollectionViewModel(SystemApiService apiCallInterface) {
        super(apiCallInterface);

    }

    /**
     * 收藏
     */
    public void collectProductList(){
        Map<String, Object> map = new HashMap<>();
        addSubscribe(apiCallInterface.collectProductList(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<CollectionModule>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<CollectionModule> collectionModuleList = (List<CollectionModule>) resultEntity.getData();
                mCollectionModuleList.setValue(collectionModuleList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }
        }));
    }

    /**
     * 删除收藏
     */
    public void delCollectProduct(String ids){
        Map<String, Object> map = new HashMap<>();
        map.put("ids",ids);
        addSubscribe(apiCallInterface.delCollectProduct(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<CollectionModule>>>() {
                    @Override
                    public void onNextData(ResultEntity resultEntity) {
                        //收藏列表
                        collectProductList();
                    }

                    @Override
                    public void onErrorNet(Throwable t, String netMsg) {

                    }
                }));
    }
}
